<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>标题生成器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        /* 遮罩层 */
        .overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1;
        }

        /* 弹窗样式 */
        .modal {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: #fff;
            padding: 20px;
            box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
            z-index: 2;
            width: 300px;
            text-align: center;
            border-radius: 10px;
        }

        /* 关闭按钮 */
        .close-btn {
            background-color: #f44336;
            color: white;
            border: none;
            padding: 5px 10px;
            cursor: pointer;
            border-radius: 5px;
            margin-top: 10px;
        }

        .close-btn:hover {
            background-color: #d32f2f;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            padding: 20px;
            display: flex;
            gap: 20px;
        }

        .left-panel {
            width: 300px;
        }

        .app-icon {
            width: 120px;
            height: 120px;
            background: #fff;
            border-radius: 20px;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .app-icon.active {
            background: #f2f2fd;
        }

        .icon-image {
            width: 60px;
            height: 60px;
        }

        .app-name {
            text-align: center;
            font-size: 14px;
            color: #333;
            margin-top: 8px;
        }

        textarea {
            width: 90%;
            height: 120px;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 8px;
            margin: 20px 0;
            resize: none;
            font-size: 14px;
        }

        .generate-btn {
            background: #5048e5;
            color: white;
            border: none;
            padding: 10px 24px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
        }

        .right-panel {
            flex: 1;
            background: linear-gradient(to right, #eef0fd, #ece8fe);
            border-radius: 12px;
            padding: 20px;
        }

        .result-title {
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 20px;
        }

    </style>
    <script src="qrc:///qtwebchannel/qwebchannel.js"></script>
</head>
<body>
<div id="overlay" class="overlay" onclick="closeModal()"></div>

<div id="modal" class="modal">
    <p id="message">消息弹窗</p>
    <!-- TODO: 调整消息弹窗样式 -->
    <button class="close-btn" onclick="closeModal()">关闭</button>
</div>
<div class="left-panel">
    <div class="app-icon xiaohongshu">
        <img src="../../images/小红书.svg" alt="xhs" class="icon-image">
    </div>
    <div class="app-icon douyin">
        <img src="../../images/抖音.svg" alt="dy" class="icon-image">
    </div>
    <div class="app-icon wechat">
        <img src="../../images/公众号.svg" alt="wechat" class="icon-image">
    </div>
    <label>
        <textarea placeholder="请输入标题描述" id="input-content"></textarea>
    </label>
    <button class="generate-btn" onclick="general()">立即生成</button>
</div>
<div class="right-panel" id="output-content">
    <div class="result-title"></div>
</div>
<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function () {
        let platform = "xhs";
        new QWebChannel(parent.qt.webChannelTransport, function (channel) {
            Bridge = channel.objects.Bridge;

            Bridge.started.connect(function (msg) {
                showModal(msg)
            });
            Bridge.finished.connect(function (msg) {
                showModal(msg)
            });
            Bridge.failed.connect(function (msg) {
                showModal(msg)
            });
            Bridge.result.connect(function (content) {
                document.getElementById("output-content").text = content;
                // TODO: 显示结果标题
            })

            window.general = function () {
                let desc = document.getElementById("input-content").value;
                if (!desc || desc.trim() === '') {
                    showModal("请输入内容");
                    return;
                }
                Bridge.general_write(platform, "title", desc);
            }
        });

        // 获取所有app图标和结果标题
        const appIcons = document.querySelectorAll('.app-icon');

        // 为每个图标添加点击事件
        appIcons.forEach(icon => {
            icon.addEventListener('click', () => {
                // 移除所有图标的active类
                appIcons.forEach(i => i.classList.remove('active'));
                // 给当前点击的图标添加active类
                icon.classList.add('active');
                // 更新结果标题
                platform = icon.querySelector('img').alt;
                alert(platform)
            });
        });

        // 默认选中小红书
        document.querySelector('.app-icon').classList.add('active');
        window.showModal = function (message) {
            document.getElementById("message").innerText = message;
            document.getElementById("overlay").style.display = "block";
            document.getElementById("modal").style.display = "block";
        };

        window.closeModal = function () {
            document.getElementById("overlay").style.display = "none";
            document.getElementById("modal").style.display = "none";
        };
    });
</script>
</body>
</html> 